package main

import "fmt"

/* 1480. 一维数组的动态和，https://leetcode.cn/problems/running-sum-of-1d-array/ */

func ExecQ1480() {
	arr1 := []int{1, 2, 3, 4}
	fmt.Println(runningSum(arr1))

	arr2 := []int{1, 1, 1, 1, 1}
	fmt.Println(runningSum(arr2))

	arr3 := []int{3, 1, 2, 10, 1}
	fmt.Println(runningSum(arr3))
}

// 我写的
func runningSum1(nums []int) []int {
	rst := make([]int, len(nums))
	for i := range nums {
		tmp := 0
		for k := 0; k <= i; k++ {
			tmp += nums[k]
		}
		rst[i] = tmp
	}
	return rst
}

// 官方的
func runningSum(nums []int) []int {
	for i := 1; i < len(nums); i++ {
		nums[i] = nums[i-1] + nums[i]
	}
	return nums
}
